//
//  LiveViewController.m
//  UIA段项目 墨家天气
//
//  Created by dllo on 15/8/20.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "LiveViewController.h"
#import "AddCityLayout.h"

#import "AsyncURLconnection.h"
#import "LiveCollectionCell.h"
#import "UIImageView+WebCache.h"
#import "URL.h"
#import "DetailViewController.h"
#import "MJRefresh.h"

@interface LiveViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UIScrollViewDelegate,AsyncURLconnectionDelegate,LiveCollectioCellDelegate>
@property (nonatomic,retain)UIView *headerView;
@property (nonatomic,retain)UILabel *shike;
@property (nonatomic,retain)UILabel *remen;
@property (nonatomic,retain)UICollectionView *collect;
@property (nonatomic,retain)UICollectionView *rightCollection;

@end
@implementation LiveViewController
-(void)dealloc
{
    [_headerView release];
    [_shike release];
    [_remen release];
    [_collect release];
    [_rightCollection release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        self.arr = [NSMutableArray array];
        self.lunBosendTodic = [NSMutableDictionary dictionary];
        self.sendToDic  = [NSMutableDictionary dictionary];
        self.url = [NSMutableDictionary dictionary];
     
    }
    
    return self;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addCollectionView];
    [self addHeaderView];



}


- (void)addHeaderView
{
    
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60 * OffHeight)];
    _headerView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [self.view addSubview:_headerView];
    [_headerView release];
        
    self.shike = [[UILabel alloc]initWithFrame:CGRectMake(150 * OffWidth, 18 * OffHeight, 40 * OffWidth, 40 * OffHeight)];
    _shike.text = @"时刻";
    _shike.font = [UIFont systemFontOfSize:17 * OffWidth];
    _shike.textColor = [UIColor whiteColor];
    _shike.userInteractionEnabled = YES;
    [self.headerView addSubview:_shike];
    [_shike release];
    
        
    
    self.remen = [[UILabel alloc]initWithFrame:CGRectMake(190 * OffWidth, 18 * OffHeight, 40 * OffWidth, 40 * OffHeight)];
    _remen.text = @"热门";
    _remen.font = [UIFont systemFontOfSize:17 * OffWidth];

    _remen.textColor = [UIColor grayColor];
    _remen.userInteractionEnabled = YES;
    [self.headerView addSubview:_remen];
    [_remen release];
    
    
    

    
}


- (void)addCollectionView
{
   
        
   
    
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
        flow.itemSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
        [flow setMinimumLineSpacing:0];
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collect = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flow];
    

     self.collect.delegate = self;
     self.collect.dataSource = self;
     self.collect.pagingEnabled = YES;
     [self.collect registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"dd"];
    UIImageView *imageV = [[UIImageView alloc]init];
    imageV.image = [UIImage imageNamed:@"789.jpg"];
    [self.collect setBackgroundView:imageV];
    
    UIBlurEffect *ef = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effV = [[UIVisualEffectView alloc]initWithEffect:ef];
    //    effV.alpha = 1;
    effV.frame = [UIScreen mainScreen].bounds;
    [imageV addSubview:effV];
    

    
    
    //注册冲泳池
    [ self.collect registerClass:[LiveCollectionCell class] forCellWithReuseIdentifier:@"re"];
    [self.view addSubview: self.collect];
     
    [flow release];
    [_collect release];
    
    
}




/******************         本cell 没有任何赋值   **************************/


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    LiveCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"re" forIndexPath:indexPath];
    
 

    if (indexPath.item == 0) {
        self.shike.textColor = [UIColor whiteColor];
        self.remen.textColor = [UIColor grayColor];
        
        //*******    向liveCollectionView传时刻的数据
       
        
        
        
        
        [self.sendToDic setObject:@"0" forKey:@"trim_user"];
        [self.sendToDic setObject:@"3817130083" forKey:@"source"];
        [self.sendToDic setObject:@"3879710997886174%2C3879705364998344%2C3879674058434059%2C3879664336154353%2C3879650252508566%2C3879625216382691%2C3879624817414541%2C3879618794299972%2C3879505225697285%2C3879504818537438%2C3879497072086998%2C3879402880525982%2C3879399717539511%2C3879397725362863%2C3879386971472729%2C3879375684009117%2C3879365832485206%2C3879365609766651%2C3879363588081736%2C3879363432467858" forKey:@"ids"];
        [self.sendToDic setObject:@"_2AkMigJ_ff8NhqwJRmPoRyGPqbYV-yAjEiebDAH_sJxI3HlEH7CnJKHFTOjegVIEvH7vlmD3KVgn5" forKey:@"access_token"];
        [self.lunBosendTodic setObject:@"iOS" forKey:@"channel"];
        
        
        
        [self.url setObject:@"http://api.bohejiaju.com/v1/banners" forKey:@"lunbo"];
        [self.url setObject:@"https://api.weibo.com/2/statuses/show_batch.json" forKey:@"feilunbo"];
        
   
        
        
        self.sendToArr = [NSMutableArray arrayWithObjects:self.sendToDic,self.lunBosendTodic,self.url, nil];
         self.temp = indexPath.item;
        [cell sendValueForDic:self.sendToArr temp:self.temp];
        

#warning 上拉加载
        [cell.smallCollect addFooterWithCallback:^{
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                
                
                [self.sendToDic setObject:@"0" forKey:@"trim_user"];
                [self.sendToDic setObject:@"3817130083" forKey:@"source"];
                [self.sendToDic setObject:@"3884564587550949%2C3884561136611250%2C3884550692657036%2C3884541368767126%2C3884497890404132%2C3884493557768313%2C3884487097864114%2C3884480944722007%2C3884467259608189%2C3884453723786070%2C3884448943014499%2C3884447746947660%2C3884430802042590%2C3884424053645492%2C3884422183300021%2C3884416428524003%2C3884414234952016%2C3884401395869672%2C3884398376021449%2C3884343313770535" forKey:@"ids"];
                [self.sendToDic setObject:@"_2AkMigJ_ff8NhqwJRmPoRyGPqbYV-yAjEiebDAH_sJxI3HlEH7CnJKHFTOjegVIEvH7vlmD3KVgn5" forKey:@"access_token"];
                [self.lunBosendTodic setObject:@"iOS" forKey:@"channel"];
                
                
                
                [self.url setObject:@"http://api.bohejiaju.com/v1/banners" forKey:@"lunbo"];
                [self.url setObject:@"https://api.weibo.com/2/statuses/show_batch.json" forKey:@"feilunbo"];
                self.sendToArr = [NSMutableArray arrayWithObjects:self.sendToDic,self.lunBosendTodic,self.url, nil];
                 self.temp = indexPath.item;
                [cell sendValueForDic:self.sendToArr temp:self.temp];
                
                
                
                
            });
        }];

        cell.daili = self;
       
        return cell;
        
        
        
    }else{
        self.shike.textColor = [UIColor grayColor];
        self.remen.textColor = [UIColor whiteColor];


        self.lunBosendTodic = [NSMutableDictionary dictionary];
        self.sendToDic  = [NSMutableDictionary dictionary];
        self.url = [NSMutableDictionary dictionary];
        
        [self.sendToDic setObject:@"8d88c0b83de0e76748297e65481b950a" forKey:@"sign"];
        [self.sendToDic setObject:@"CHXX0116" forKey:@"citycode"];
        [self.sendToDic setObject:@"20" forKey:@"limit"];
        [self.sendToDic setObject:@"868033019886185" forKey:@"uid"];
        [self.sendToDic setObject:@"tq" forKey:@"pd"];
        [self.sendToDic setObject:@"1440563356" forKey:@"ts"];
        [self.sendToDic setObject:@"1" forKey:@"page"];
        [self.sendToDic setObject:@"517276c07b762" forKey:@"api_key"];
        [self.sendToDic setObject:@"5010" forKey:@"pt"];
        [self.sendToDic setObject:@"4.4.4" forKey:@"sv"];
        [self.sendToDic setObject:@"P400" forKey:@"pid"];
        [self.sendToDic setObject:@"3.719" forKey:@"pv"];


        
        [self.lunBosendTodic setObject:@"iOS" forKey:@"channel"];
        [self.url setObject:@"http://api.bohejiaju.com/v1/banners" forKey:@"lunbo"];
        [self.url setObject:@"http://forecast.sina.cn/app/papa/2/subject.php" forKey:@"feilunbo"];

        
        
        self.sendToArr = [NSMutableArray arrayWithObjects:self.sendToDic,self.lunBosendTodic,self.url, nil];
        self.temp = indexPath.item;
        [cell sendValueForDic:self.sendToArr temp:self.temp];
        
        cell.daili = self;
      
        return cell;
 
    }
    
   
    
 #warning 上拉加载     
    

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return 2;
}

- (void)GotoDetailWithArr:(NSMutableArray *)arr temp:(NSInteger)temp index:(NSInteger )index
{
    DetailViewController *detail = [[DetailViewController alloc]init]; 
    detail.arr =  arr;
    detail.temp = temp;
    
    detail.index = index;
    [detail autorelease];
    [self presentViewController:detail animated:YES completion:nil];

}




@end
